home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / xpk_source / xpkmaster / libdata.a < prev    next >
Text File  |  1998-02-08  |  11KB  |  364 lines

  1. * Routinesheader
  2. *
  3. *    Name:        libdata.a
  4. *    Main:        xpkmaster
  5. *    Versionstring:    $VER: libdata.a 4.26 (27.01.1998)
  6. *    Author:        SDI
  7. *    Distribution:    PD
  8. *    Description:    all the library startup data
  9. *
  10. * 3.10  28.10.96 : first real version
  11. * 3.11  25.11.95 : recompiled with SAS 6.57
  12. * 4.0   29.12.96 : added some new functions, OS2.0 only, corrected error in
  13. *    locale handling (Ooops - (A2) instead of A2 :-)
  14. * 4.1   11.01.97 : hopefully fixed buffer overworking bug
  15. * 4.2   30.01.97 : mem bug still was not completely fixed
  16. * 4.3   01.03.97 : changed semaphore structure
  17. * 4.4   09.03.97 : added preferences stuff
  18. * 4.5   23.03.97 : fixed Enforcer Hits
  19. * 4.6   28.03.97 : fixed prefs stuff
  20. * 4.7   31.03.97 : changed XpkQuery and Password stuff
  21. * 4.8   02.04.97 : changed a lot, removed some stuff
  22. * 4.9   03.04.97 : preferences buffers now via hookread and not direct
  23. * 4.10  04.04.97 : minor fixes
  24. * 4.11  10.04.97 : Password request now restores FirstScreen
  25. * 4.12  28.04.97 : fixed mem-corrupt bug and changed progress time calc
  26. * 4.13  11.05.97 : fixed reported errors in Expunge code
  27. * 4.14  06.06.97 : added DEBUG output
  28. * 4.15  18.08.97 : changed RecogFunc interface a bit
  29. * 4.16  21.08.97 : did a big mistake in version 4.15 (USER mode did not work)
  30. * 4.17  15.10.97 : PassRequest now uses timer.device
  31. * 4.18  07.11.97 : TimeOut of 0 now means again no timeout
  32. * 4.19  19.12.97 : added xfdmaster support, code cleanup and changes
  33. * 4.20  27.12.97 : fixed bug in Autopassword and added title line to passreq
  34. * 4.21  01.01.98 : USER information is a bit better now
  35. * 4.22  09.01.98 : added ability to pass decrunch keys, PassRequest uses
  36. *    gadtools now and show stars
  37. * 4.23  18.01.98 : added 2 new password flags
  38. * 4.24  21.01.98 : added password verification
  39. * 4.25  24.01.98 : fixed xfdmaster support a bit, removed PP support
  40. * 4.26  27.01.98 : brings better errors in USER mode
  41.  
  42.     NOLIST
  43.     INCLUDE    "AINCLUDE:IncDirs.i" *sets all includedirs, needed for my ASM
  44.     INCLUDE "exec/types.i"
  45.     INCLUDE "exec/initializers.i"
  46.     INCLUDE "exec/libraries.i"
  47.     INCLUDE "exec/lists.i"
  48.     INCLUDE "exec/alerts.i"
  49.     INCLUDE "exec/resident.i"
  50.     INCLUDE "dos/dos.i"
  51.     INCLUDE "libraries/locale.i"
  52.     INCLUDE    "lvo.i"
  53.     LIST
  54.  
  55. VERSION        EQU    4
  56. REVISION    EQU    26
  57. MINOSVERSION    EQU    37
  58.  
  59. STRINGANZ    EQU    11
  60. STRINGSTART    EQU    0
  61. ERRSTRINGANZ    EQU    35
  62. ERRSTRINGSTART    EQU    200
  63.  
  64. VSTRING    MACRO
  65.         DC.B    'xpkmaster 4.26 (27.01.1998)',13,10,0
  66.     ENDM
  67.  
  68.     XDEF    _DOSBase,_GadToolsBase,_IntuitionBase,_UtilityBase,_XpkBase
  69.     XDEF    _MainVersion
  70.  
  71.     XREF    _LIBXpkExamine,_LIBXpkPack
  72.     XREF    _LIBXpkUnpack,_LIBXpkOpen,_LIBXpkRead,_LIBXpkWrite
  73.     XREF    _LIBXpkSeek,_LIBXpkClose,_LIBXpkQuery
  74.     XREF    _LIBXpkAllocObject,_LIBXpkFreeObject
  75.     XREF    _LIBXpkFault,_LIBXpkPrintFault
  76.     XREF    _LIBXpkPassRequest
  77.     XREF    _strings,_XpkErrs
  78.  
  79.     SECTION    "XPK_LibStart",Code
  80. Start    MOVEQ    #-1,d0    ; return an error in case someone
  81.     RTS        ; tried to run as a program
  82.  
  83. ; A romtag structure.  Both "exec" and "ramlib" look for this structure to
  84. ; discover magic constants about you (such as where to start running you
  85. ; from...).
  86.  
  87. RomTag        DC.W    RTC_MATCHWORD    ; UWORD rt_MatchWord
  88.         DC.L    RomTag        ; APTR  rt_MatchTag
  89.         DC.L    ENDCODE        ; APTR  rt_EndSkip
  90.         DC.B    RTF_AUTOINIT    ; UBYTE rt_Flags
  91. _MainVersion    DC.B    VERSION        ; UBYTE rt_Version
  92.         DC.B    NT_LIBRARY    ; UBYTE rt_type
  93.         DC.B    0        ; BYTE  rt_Pri
  94.         DC.L    LibName        ; APTR  rt_Name
  95.         DC.L    IDString    ; APTR  rt_IDString
  96.         DC.L    InitTable    ; APTR  rt_Init  table for InitResident()
  97.  
  98. IDString    VSTRING
  99. LibName        DC.B    'xpkmaster.library',0
  100. DosName        DC.B    'dos.library',0
  101. INTUITIONNAME    DC.B    'intuition.library',0
  102. GADTOOLSNAME    DC.B    'gadtools.library',0
  103. UTILITYNAME    DC.B    'utility.library',0
  104. LOCALENAME    DC.B    'locale.library',0
  105. CATALOGNAME    DC.B    'xpkmaster.catalog',0
  106.           CNOP    0,2    ; word alignement
  107.  
  108. ; The romtag specified that we were "RTF_AUTOINIT". This means that the
  109. ; rt_Init structure member points to one of these tables below. If the
  110. ; AUTOINIT bit was not set then RT_INIT would point to a routine to run.
  111.  
  112. InitTable:
  113.     DC.L    LIB_SIZE        ; size of library base data space
  114.     DC.L    funcTable        ; pointer to function initializers
  115.     DC.L    dataTable        ; pointer to data initializers
  116.     DC.L    initRoutine        ; routine to run
  117.  
  118. funcTable:
  119. ;------ standard system routines
  120.     DC.L    Open
  121.     DC.L    Close
  122.     DC.L    Expunge
  123.     DC.L    Null
  124. ;------ my libraries definitions
  125.     DC.L    Null
  126.     DC.L    _LIBXpkExamine
  127.     DC.L    _LIBXpkPack
  128.     DC.L    _LIBXpkUnpack
  129.     DC.L    _LIBXpkOpen
  130.     DC.L    _LIBXpkRead
  131.     DC.L    _LIBXpkWrite
  132.     DC.L    _LIBXpkSeek
  133.     DC.L    _LIBXpkClose
  134.     DC.L    _LIBXpkQuery
  135.     DC.L    _LIBXpkAllocObject
  136.     DC.L    _LIBXpkFreeObject
  137.     DC.L    _LIBXpkPrintFault
  138.     DC.L    _LIBXpkFault
  139.     DC.L    _LIBXpkPassRequest
  140. ;------ function table end marker
  141.     DC.L    -1
  142.  
  143. ; The data table initializes static data structures. The format is specified
  144. ; in exec/InitStruct routine's manual pages. The INITBYTE/INITWORD/INITLONG
  145. ; routines are in the file "exec/initializers.i". The first argument is the
  146. ; offset from the library base for this byte/word/long. The second argument
  147. ; is the value to put in that cell. The table is null terminated.
  148.  
  149. dataTable:
  150.     INITBYTE    LN_TYPE,NT_LIBRARY
  151.     INITLONG    LN_NAME,LibName
  152.     INITBYTE    LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  153.     INITWORD    LIB_VERSION,VERSION
  154.     INITWORD    LIB_REVISION,REVISION
  155.     INITLONG    LIB_IDSTRING,IDString
  156.     DC.L        0
  157.  
  158. ; This routine gets called after the library has been allocated. The library
  159. ; pointer is in D0. The segment list is in A0. If it returns non-zero then
  160. ; the library will be linked into the library list.
  161.  
  162. initRoutine:
  163. ;------ get the library pointer into a convenient A register
  164.     MOVEM.L    A2/D6/D7/A6/A5,-(A7)
  165.     MOVEA.L    D0,A5
  166.     MOVE.L    D0,_XpkBase        ; init XpkBase for internal calls
  167. ;------ save a pointer to our loaded code
  168.     MOVE.L    A0,SegList
  169. ;
  170. ; specific openings here
  171. ;
  172.     MOVEA.L    4.W,A6
  173.     MOVEQ    #MINOSVERSION,D0
  174.     LEA    DosName(PC),A1
  175.     JSR    _LVOOpenLibrary(A6)
  176.     MOVE.L    D0,_DOSBase
  177.     BEQ.W    .kill
  178.     MOVEQ    #MINOSVERSION,D0
  179.     LEA    GADTOOLSNAME(PC),A1
  180.     JSR    _LVOOpenLibrary(A6)
  181.     MOVE.L    D0,_GadToolsBase
  182.     BEQ.W    .kill
  183.     MOVEQ    #MINOSVERSION,D0
  184.     LEA    INTUITIONNAME(PC),A1
  185.     JSR    _LVOOpenLibrary(A6)
  186.     MOVE.L    D0,_IntuitionBase
  187.     BEQ.B    .kill
  188.     MOVEQ    #MINOSVERSION,D0
  189.     LEA    UTILITYNAME(PC),A1
  190.     JSR    _LVOOpenLibrary(A6)
  191.     MOVE.L    D0,_UtilityBase
  192.     BEQ.B    .kill
  193.     MOVEQ    #38,D0            * needed locale.library version
  194.     LEA    LOCALENAME(PC),A1
  195.     JSR    _LVOOpenLibrary(A6)
  196.     MOVE.L    D0,_LocaleBase
  197.     BEQ.B    .endok
  198.     MOVEA.L    D0,A6
  199.     SUBA.L    A0,A0
  200.     JSR    _LVOOpenLocale(A6)
  201.     MOVE.L    D0,_Locale
  202.     BEQ.B    .endok
  203.     MOVEA.L    D0,A0
  204.     LEA    CATALOGNAME(PC),A1
  205.     LEA    CATALOGTAGS(PC),A2
  206.     JSR    _LVOOpenCatalogA(A6)
  207.     MOVE.L    D0,_Catalog
  208.     BEQ.B    .endok
  209.     MOVEQ    #STRINGANZ-1,D6
  210.     MOVEQ    #STRINGSTART,D7
  211.     LEA    _strings,A2
  212.     BSR.B    DoLocale
  213.     MOVEQ    #ERRSTRINGANZ-1,D6
  214.     MOVE.L    #ERRSTRINGSTART,D7
  215.     LEA    _XpkErrs,A2
  216.     BSR.B    DoLocale
  217.  
  218. .endok    MOVE.L    A5,D0
  219. .end    MOVEM.L    (A7)+,A2/D6/D7/A6/A5
  220.     RTS
  221. .kill    BSR.W    KillLibs
  222.     MOVEQ    #0,D0
  223.     BRA.B    .end
  224.  
  225. DoLocale    MOVE.L    _Catalog(PC),A0
  226.         MOVE.L    D7,D0
  227.         MOVEA.L    (A2),A1
  228.         ADDQ.L    #1,D7
  229.         JSR    _LVOGetCatalogStr(A6)
  230.         MOVE.L    D0,(A2)+
  231.         DBRA    D6,DoLocale
  232.         RTS
  233.  
  234. ; here begins the system interface commands. When the user calls
  235. ; OpenLibrary/CloseLibrary/RemoveLibrary, this eventually gets translated
  236. ; into a call to the following routines (Open/Close/Expunge). Exec has
  237. ; already put our library pointer in A6 for us. Exec has turned off task
  238. ; switching while in these routines (via Forbid/Permit), so we should not
  239. ; take too long in them.
  240.  
  241. ; Open returns the library pointer in D0 if the open was successful. If the
  242. ; open failed then null is returned. It might fail if we allocated memory
  243. ; on each open, or if only one application could have the library open at
  244. ; a time...
  245.  
  246. Open:        ; (libptr:A6, version:D0)
  247. ;------ mark us as having another opener
  248.     ADDQ.W    #1,LIB_OPENCNT(A6)
  249.     BCLR    #LIBB_DELEXP,LIB_FLAGS(A6)
  250.     MOVE.L    A6,D0
  251.     RTS
  252.  
  253. ; There are two different things that might be returned from the Close
  254. ; routine. If the library is no longer open and there is a delayed expunge
  255. ; then Close should return the segment list (as given to Init). Otherwise
  256. ; close should return NULL.
  257.  
  258. Close:        ; (libptr:A6)
  259. ;------ set the return value
  260.     MOVEQ    #0,D0
  261. ;------ mark us as having one fewer openers
  262.     SUBQ.W   #1,LIB_OPENCNT(A6)
  263. ;------ see if there is anyone left with us open
  264.     BNE.B    .OneLeft
  265. ;------ do the expunge
  266.     BTST    #LIBB_DELEXP,LIB_FLAGS(A6)
  267.     BEQ.B    .OneLeft
  268.     BSR.B    Expunge
  269. .OneLeft
  270.     RTS
  271.  
  272. ; There are two different things that might be returned from the Expunge
  273. ; routine. If the library is no longer open then Expunge should return the
  274. ; segment list (as given to Init). Otherwise Expunge should set the delayed
  275. ; expunge flag and return NULL.
  276. ; One other important note: because Expunge is called from the memory
  277. ; allocator, it may NEVER Wait() or otherwise take long time to complete.
  278.  
  279. Expunge:    ; (libptr: A6)
  280.     MOVEM.L    D2/A5/A6,-(A7)
  281.     MOVEA.L    A6,A5
  282.     MOVEA.L    4.W,A6
  283. ;------ see if anyone has us open
  284.     TST.W    LIB_OPENCNT(A5)
  285.     BEQ.B    .DoIt
  286.     BSET    #LIBB_DELEXP,LIB_FLAGS(A5)
  287.     MOVEQ    #0,D0
  288.     BRA.B    .Expunge_End
  289. .DoIt
  290. ;------ go ahead and get rid of us.  Store our seglist in D2
  291.     MOVE.L    SegList(PC),D2
  292. ;------ unlink from library list
  293.     MOVEA.L    A5,A1
  294.     JSR    _LVORemove(A6)
  295. ;
  296. ; device specific closings here...
  297.     BSR.B    KillLibs
  298. ;
  299. ;------ free our memory
  300.     MOVEQ    #0,D0
  301.     MOVEA.L    A5,A1
  302.     MOVE.W    LIB_NEGSIZE(A5),D0
  303.     SUBA.L    D0,A1
  304.     ADD.W    LIB_POSSIZE(A5),D0
  305.     MOVEA.L    4.W,A6
  306.     JSR    _LVOFreeMem(A6)
  307. ;------ set up our return value
  308.     MOVE.L    D2,D0
  309.  
  310. .Expunge_End
  311.     MOVEM.L    (A7)+,D2/A5/A6
  312.     RTS
  313.  
  314. KillLibs:    MOVEA.L    4.W,A6
  315.         MOVEA.L    _GadToolsBase(PC),A1
  316.         MOVE.L    A1,D0                ; for checking
  317.         BEQ.B    .intuition
  318.         JSR    _LVOCloseLibrary(A6)
  319. .intuition:    MOVEA.L    4.W,A6
  320.         MOVEA.L    _IntuitionBase(PC),A1
  321.         MOVE.L    A1,D0                ; for checking
  322.         BEQ.B    .utility
  323.         JSR    _LVOCloseLibrary(A6)
  324. .utility    MOVEA.L    _UtilityBase(PC),A1
  325.         MOVE.L    A1,D0
  326.         BEQ.B    .dos
  327.         JSR    _LVOCloseLibrary(A6)
  328. .dos        MOVEA.L    _DOSBase(PC),A1
  329.         MOVE.L    A1,D0
  330.         BEQ.B    .locale
  331.         JSR    _LVOCloseLibrary(A6)
  332. .locale        MOVEA.L    _LocaleBase(PC),A6
  333.         MOVE.L    A6,D0
  334.         BEQ.B    .endlibs
  335.         MOVEA.L    _Catalog(PC),A0
  336.         MOVE.L    A0,D0
  337.         BEQ.B    .closelocale
  338.         JSR    _LVOCloseCatalog(A6)
  339. .closelocale    MOVEA.L    _Locale(PC),A0
  340.         MOVE.L    A0,D0
  341.         BEQ.B    .closelibrary
  342.         JSR    _LVOCloseLocale(A6)
  343. .closelibrary    MOVEA.L    A6,A1
  344.         MOVEA.L    4.W,A6
  345.         JSR    _LVOCloseLibrary(A6)
  346. .endlibs    RTS
  347.  
  348. Null:    MOVEQ    #0,D0
  349.     RTS
  350.  
  351. CATALOGTAGS:    DC.L    OC_Version,2,TAG_DONE
  352. SegList:    DC.L    0    * set by Init
  353. _Catalog:    DC.L    0    * access only by Init
  354. _Locale:    DC.L    0    * or by Expunge, no need to access
  355. _LocaleBase:    DC.L    0    * locale in program
  356. _DosBase:
  357. _DOSBase:    DC.L    0    * set by Init    these are library globals
  358. _UtilityBase:    DC.L    0    * set by Init    in C Code read only !!!
  359. _XpkBase:    DC.L    0    * set by Init
  360. _GadToolsBase    DC.L    0    * set by Init
  361. ENDCODE:
  362. _IntuitionBase:    DC.L    0    * set by Init
  363.         END
  364.